import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

def calcExl(epath, figurePath):

    data = pd.read_excel(epath)

    name = ['pic_date', 'Granular sludge', 'Epistylis', 'Floc', 'Rotifer', 'Filamentous bacteria']  # 指定行列名

    mydata = pd.DataFrame(data=data, columns=name)

    mydataT = np.transpose(mydata)
    print(mydataT)

    x = mydata['pic_date']
    y1 = mydata['Granular sludge']
    y2 = mydata['Epistylis']
    y3 = mydata['Floc']
    y4 = mydata['Rotifer']
    y5 = mydata['Filamentous bacteria']


    plt.plot(x, y1, c='black', marker='o', linestyle='-', label='Granular sludge')
    plt.plot(x, y2, c='red', marker='o', linestyle='-', label='Epistylis')
    plt.plot(x, y3, c='chocolate', marker='o', linestyle='-', label='Floc')
    plt.plot(x, y4, c='gold', marker='o', linestyle='-', label='Rotifer')
    plt.plot(x, y5, c='olivedrab', marker='o', linestyle='-', label='Filamentous bacteria')


    font1 = {'family': 'Times New Roman', 'weight': 'normal', 'size': 10}
    plt.xticks(fontproperties='Times New Roman', fontsize=10)
    plt.yticks(fontproperties='Times New Roman', fontsize=10)

    plt.xlabel(u'Date', font1)
    plt.ylabel(u'Number', font1)

    plt.legend(loc=2, prop=font1)  # 图例展示位置，数字代表第几象限

    # change x internal size
    plt.gca().margins(x=0)
    plt.gcf().canvas.draw()

    # set size
    maxsize = 220
    m = 0.3
    N = len(x)
    s = maxsize / plt.gcf().dpi * N + 2 * m
    margin = m / plt.gcf().get_size_inches()[0]

    plt.gcf().subplots_adjust(left=margin, right=1. - margin)
    plt.gcf().set_size_inches(s, plt.gcf().get_size_inches()[1])

    plt.savefig(figurePath)
    plt.close()